<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%-- <link rel="stylesheet"
	href="<%=request.getContextPath() %>/WEB-ROOT/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet"
	href="<%=request.getContextPath() %>/WEB-ROOT/css/common.css">
<link rel="stylesheet"
	href="<%=request.getContextPath() %>/WEB-ROOT/bootstrap/css/treeview.css"> --%>
<%
HttpSession s = request.getSession(); 
%>
<body class="full" id="content">
	<div id="alert"></div>
	<div id="addDepList"></div>
	<div class="row">

		<div class="col-lg-12 col-md-12 col-sm-12 ">
		<form class="form-inline" role="form" id="selectDepVal">
				<div class="row">
					<div class="form-group inputselect col-lg-4">
					   <sec:authorize access="hasRole('ROLE_ADMIN')">
					<button type="button" class="btn btn-info btn-sm " id="addDep">
							<span class="glyphicon glyphicon-user"></span> 新增角色信息
						</button>
						 </sec:authorize>
					</div>
				</div>
			</form>
			<form class="form-inline" role="form"></form>
			<div class="table-responsive " style="margin-left: 3%; " >
				<table class="table table-hover tablefont">
					<tbody id="tableList" >
					</tbody>
				</table>
				<div style="bottom: 10%">
					<div id="paging" style="text-align: center; margin-left: 25%;">
					</div>

				</div>


			</div>

		</div>
	</div>
	<%-- <script
		src="<%=request.getContextPath() %>/WEB-ROOT/bootstrap/js/jquery-min.js"></script>
	<script
		src="<%=request.getContextPath() %>/WEB-ROOT/bootstrap/js/treeview.js"></script>
	<script
		src="<%=request.getContextPath() %>/WEB-ROOT/bootstrap/js/bootstrap.min.js"></script> --%>
	<script type="text/javascript">
	var authority = "${authority}";
	var usrname = "${username}";
		//增加
		$("#addDep").click(function(){
			 $("#addDepList").load("WEB-ROOT/html/addRole.jsp",function(){
				$("#addModel").modal({
	     	        keyboard: true
	     	    });
		})
		});
		var pageSize = 8;
		var dataUrl = "${pageContext.request.contextPath}/getrolelist";
		selectList= function(){
			initPage("0",pageSize,dataUrl);
		};
		initPage("0", pageSize, dataUrl);
		
	
		function initPage(num, ps, url) {
			//alert(num);
			$.ajax({
				url : url,
				type : "GET",
				 data : "currentPage=" + num + "&pageSize=" + ps ,
				contentType : "application/json;charset=utf-8",
				success : function(msg) {
					//alert(data.username);
					initTable(msg);
					// if("[ROLE_USER]"==authority){
					// 	 var mi=1;
					// 	 while($('#tableList tr:eq('+ mi + ') td:eq(1)').text()!=""){
					// 		 if($('#tableList tr:eq('+ mi + ') td:eq(1)').text()!=usrname){
					// 				$('#tableList tr:eq('+ mi + ')').text("");
					// 		 }
					// 		 mi++;
					//
					// 	}
					// 	$("#paging").attr("style","display:none;");
					// }


				},
				error : function(e) {
					console.log(e)
					alert("失败");
				}
			});
		}
		//初始化表格
		function initTable(data) {
			//var obj = eval("("+data+")");
			data = JSON.parse(data);
			var obj = data.arrayList;
			var page = data.pageInfo;
			console.log(data)
			//alert(page.totalPage);
			//alert(page.totalPage)
			//table
			myTable = $.lTable(
							'#tableList',
							{
								data : obj 
								,
								title : [
										"roleid",
										"rolename",
										"rolevalue",
										"<button  class='btn btn-info btn-sm editDepa'  ID='editDepa' onclick='updF(id)'><span class='glyphicon glyphicon-user'></span> 编辑</button> <button  class='btn btn-info btn-sm delDepa' ID='delDepa' onclick='delF(id)'><span class='glyphicon glyphicon-user'></span>删除</button>" ] ,
								name : [ "角色编号", "角色名","角色值",
								         "_opt" ],
								tid : "roleid",
								checkBox : "roleid"
							});
			$.lPaging('#paging',
			{
				pageNumber : page.currentPage 
				,
				totalPage : page.totalPage 
				,
				countSize : 8
				,
				count : page.totalResult,
				inputSearch : false
				,
				onPageChange : function(num) {
					initPage(num, pageSize, dataUrl,localDepNum,localDepName);
				}
			});
		}
		function updF(id) {
			$.ajax({
						type : "POST", 
						url : "${pageContext.request.contextPath}/getrolebyid",
						data : id,
						async : true,
						// dataType:"json",   
						contentType : "application/json;charset=utf-8",
						success : function(msg) {

							/* $("#alertText").text(msg);
							$("#alertModel").modal({
							     keyboard: true
							 }); */
							 $("#addDepList").load(
										"WEB-ROOT/html/addRole1.jsp",
										function() {
											$("#addModel").modal({
												keyboard : true
											});
											 var newUpdateDate = new Date();
											var userInfo = JSON.parse(msg);
											if (userInfo != null) {
												$("#roleid").val(
														userInfo.roleid);
												$("#rolename").val(
														userInfo.rolename);
												$("#rolevalue").val(
														userInfo.rolevalue);
												$("#submitType").val("PUT")
											}
											getSelectInput();
										})
							/*  $("#alertText").text(msg);
							$("#alertModel").modal({
							      keyboard: true
							  }); */

						},
						error : function(msg) {
							alert("bb");
						}
					});
			}
	    function delF(id) {
			$("#alert").load("WEB-ROOT/common/alert.jsp",
					function(response, status, xhr) {
						$('#alert').html(response);
					});
			$.ajax({
						type : "DELETE", 
						url : "${pageContext.request.contextPath}/deleteRole",
						data : id,
						async : true,
				        dataType:"json",
						contentType : "application/json;charset=utf-8",
						success : function(msg) {
							var  signal="";
							if(msg=="success"){
								signal="更新成功"
							}else {
								signal="更新失败"
							}
							$("#alertText").text(signal);
							$("#alertModel").modal({
								keyboard : true
							});
						},
						error : function(msg) {
							$("#alertText").text("更新失败");
							$("#alertModel").modal({
								keyboard : true
							});
						}
					});
			}
	</script>
</body>





